<?php

namespace Admin\Controller;
//use Think\Controller;
use Think\Think;
use Tools\AdminController;


class  RoleController extends AdminController {
    function showlist() {
        $info=D('Role')->select();

        $this->assign('info',$info);
        $this->display();
    }


    function distribute($role_id) {
        //展示，收集
        $role= new \Model\RoleModel();
        if(!empty($_POST)){
            //dump($_POST);
            $z=$role->saveAuth($_POST['role_id'],$_POST['auth_id']);
            if ($z){
                $this->redirect('showlist',array(),2,'权限分配成功！');
            }else{
                $this->redirect('distribute',array('ro_id=>$role_id'),2,'权限分配失败！');
            }
        }else {
            //分配权限展示表单
            //查询分配权限角色信息
            $roleinfo = $role->find($role_id);

            //查询角色已拥有权限
            $have_authids=$roleinfo['role_auth_ids'];
            $have_authids=explode(',',$have_authids);

            $auth_infoP = D('Auth')->where("auth_level=0")->select();
            $auth_infoC = D('Auth')->where("auth_level=1")->select();


            $this->assign('have_authids', $have_authids);
            $this->assign('auth_infoP', $auth_infoP);
            $this->assign('auth_infoC', $auth_infoC);
            $this->assign('roleinfo', $roleinfo);
            $this->display();
        }
    }

}